 
// import type { ResultSystemFileDuiXiang, SystemFileDuiXiang } from '@/genapi/base';
// import { planFilingsSystemSystemFileUploadbyPost } from '@/genapi/base';

import type { components } from '@/genapi/wh';
import { whManagerSystemSystemFileUploadUsingPost } from '@/genapi/wh';

/**
 * 上传接口
 * @param options
 */
export function uploadRequest(
  file: Blob,
  onUploadProgress?: (data: any) => void,
): Promise<components['schemas']['ResultSystemFileDuiXiang']> {
  const data: any = new FormData();
  data.append('file', file);
  return whManagerSystemSystemFileUploadUsingPost({
    data,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    onUploadProgress,
  });
}

/**
 * 通过资源对象格式化成URL
 *
 * @param options 资源对象
 * @param sign 	连接有效签名，登录时可忽略
 */
export function formatFilePath(options?: components['schemas']['SystemFileDuiXiang'] | string) {
  let path: string | undefined;
  if (typeof options === 'string' || typeof options === 'number') {
    path = `${options}`;
  } else if (options?.path) {
    path = options.path;
  }
  if (path) {
    return `${import.meta.env.VITE_SERVER_URL}${path}`;
  }
}
